<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    [v-cloak] {
      display: none;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <button>计算属性</button>
    <span v-show="sum ? true:false">{{getSum}}</span>

  </div>
  <script src="../vue.js"></script>
  <script>
    const app = new Vue({
      el: "#app",
      data: {
        num1: 15,
        num2: 210,
        sum: 0,
      },
      computed: {
        //计算属性不是函数，只能通过闭包传参
        //简写
        /* getSum: function () {
          return this.sum = this.num1 + this.num2;
        } */
        //完成写法
        /* getSum: {
          get: function () {
            return this.sum = 2;
          },
          set: function (val) {
            console.log(val + '112313');
            this.sum = val - 50
          }
        } */
      }
    })
  </script>
</body>

</html>